<template>
	<view>
		<view class="address-list-item" v-for="(address,index) in addressList" :key="index">
			<view class="layout">
				<view class="address-list-item-box"  @click="handleSelectedButton(address)">
					<view class="address-list-item-box-text">{{address.address}}</view>
					<view class="address-list-item-box-note">
						<view class="layout">
							<view>{{address.fullname}}</view>
							<view>{{address.telephone}}</view>
						</view>
					</view>
				</view>
				<view class="address-list-item-button"  @click="handleAddressNewButton(address)">
					<image src="/static/icon/icon-edit.png"></image>
				</view>
			</view>
		</view>
		<view class="address-button">
			<view class="address-button-tooltip" @click="handleAddressNewButton()">新地址</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fromOrderID:0,
				fromHome:"",
				addressList:[
				]
			}
		},
		onLoad(option) {
			this.fromOrderID = option.orderID
			this.fromHome = option.fromHome
			this.refreshAddressList()
		},
		methods: {
			refreshAddressList:function(){
				let _this = this;
				this.$transaction.getAddressList().then(res=>{
					if(res.code == 200){
						_this.addressList = res.data.list;
					}else{
						
					}
				})
			},
			handleAddressNewButton:function(address){
				let toUrl = "/pages/transaction/address-add/address-add"
				if(address != undefined){
					toUrl = toUrl+"?addressID="+address.ID
				}
				uni.navigateTo({
					url:toUrl
				})
			},
			handleSelectedButton:function(address){
				if(this.fromHome == "shopping"){
					uni.switchTab({
						url:"/pages/transaction/shopping/shopping"
					})
				}
				if(this.fromHome == "confirm"){
					uni.redirectTo({
						url:"/pages/transaction/confirm/confirm?orderID="+this.fromOrderID
					})
				}
			}
		}
	}
</script>

<style>
page { background: #ededed;}
.address-list-item { background: #fff; border-bottom: #ededed 1px solid; padding: 15rpx 25rpx; }
.address-list-item-box { width: 650rpx; }
.address-list-item-box-text { font-size: 18px; font-weight: bold; padding-bottom: 15rpx; }
.address-list-item-box-note { font-size: 14px; }
.address-list-item-button { width: 50rpx; height: 50rpx; padding-top: 15rpx;}
.address-list-item-button image { width: 100%; height: 100%; }

.address-button { position: fixed; background: #fff; bottom: 0; left: 0; right: 0; text-align: center; padding: 20rpx 0; }
.address-button-tooltip { background: #f30; width: 700rpx; margin: 0 auto; padding: 15rpx; border-radius: 30rpx;}
.address-button-tooltip { color: #fff; font-size: 18px; font-weight: bold;}
</style>
